import { View } from "../../../mvc/core/View";
import { GMarketButtonBar } from "./GMarketButtonBar";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { MuiEvent } from "../../../../com/mui/events/MuiEvent";
import { EventName } from "../../mvc/EventName";
import { GTextBar } from "../range/GTextBar";
import { GTextFormat } from "../../../common/GTextFormat";
import { DataEvent } from "../../events/DataEvent";
type int = number;
//class MarketTabBar
    
    export  class MarketTabBar extends View
    {
        constructor()
        {
            super();
            this._firstTagDp = [];
            this._secondTagDp = [];
            this.init();
            return;
        }

        public set firstTagDp(arg1: Array<any>)
        {
            this._firstTagDp = arg1;
            this._buttonBar.dataProvider = this._firstTagDp;
            return;
        }

        public set secondTagDp(arg1: Array<any>)
        {
            this._secondTagDp = arg1;
            return;
        }

        /* internal  */init(): void
        {
            this._buttonBar = new GMarketButtonBar();
            this._buttonBar.verticalGap = 3;
            this._buttonBar.direction = GBoxDirection.VERTICAL;
            this._buttonBar.dataProvider = this._firstTagDp;
            this._buttonBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onButtonBarSelectedHandler);
            this._buttonBar.addEventListener(EventName.MarketButtonClose, this.onButtonCloseHandler);
            this._buttonBar.addEventListener(EventName.RankBarInitEnd, this.onButtonInitEndHandler);
            addChild(this._buttonBar);
            this._textBar = new GTextBar();
            this._textBar.width = 100;
            this._textBar.verticalGap = 3;
            this._textBar.x = 0;
            this._textBar.y = 0;
            this._textBar.direction = GBoxDirection.VERTICAL;
            var loc1=new GTextFormat("", 12, 15859633);
            this._textBar.textformat = loc1;
            var loc2=new GTextFormat("", 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._textBar.normalTextformat = loc2;
            this._textBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onTextBarSelectedHandler);
            this._textBar.addEventListener(EventName.RankBarInitEnd, this.onTextInitEndHandler);
            addChild(this._textBar);
            return;
        }

        /* internal  */onButtonBarSelectedHandler(arg1: MuiEvent): void
        {
            this._btnBarSelectIdx = arg1.selectedIndex as int;
            this._textBar.dataProvider = this._secondTagDp[this._btnBarSelectIdx];
            dispatchEvent(new Object /* flash.events.Event */(EventName.RankBarInitEnd));
            return;
        }

        /* internal  */onButtonCloseHandler(arg1: DataEvent): void
        {
            this._btnBarSelectIdx = 0;
            this._buttonBar.dataProvider = this._firstTagDp;
            this._textBar.dataProvider = new Array<any>();
            dispatchEvent(new Object /* flash.events.Event */(EventName.MarketButtonClose));
            return;
        }

        /* internal  */onButtonInitEndHandler(arg1: Object /* flash.events.Event */): void
        {
            dispatchEvent(new Object /* flash.events.Event */(EventName.RankBarInitEnd));
            if (!this._isSetTwoTag) 
            {
                this._btnBarSelectIdx = 0;
            }
            return;
        }

        /* internal  */onTextBarSelectedHandler(arg1: MuiEvent): void
        {
            var loc1=this._textBar.selectedIndex;
            if (this._isSetTwoTag) 
            {
                this._isSetTwoTag = false;
            }
            else 
            {
                dispatchEvent(new DataEvent(EventName.MarketSearchTypeChange, {"oneIndex": this._buttonBar.selectedIndex, "twoIndex": loc1}));
            }
            return;
        }

        /* internal  */onTextInitEndHandler(arg1: Object /* flash.events.Event */=null): void
        {
            this._buttonBar.resetButtonPos(this._buttonBar.selectedIndex, this._textBar.height);
            var loc1=this._buttonBar.getFirstBlankPos(this._buttonBar.selectedIndex);
            this._textBar.x = loc1.x;
            this._textBar.y = loc1.y;
            if (this._twoIndex != -1) 
            {
                this._textBar.selectedIndex = this._twoIndex;
                this._twoIndex = -1;
            }
            dispatchEvent(new Object /* flash.events.Event */(EventName.RankBarInitEnd));
            return;
        }

        public reset(): void
        {
            this._buttonBar.selectedIndex = -1;
            this._buttonBar.dataProvider = this._firstTagDp;
            this._buttonBar.clear();
            this._textBar.dataProvider = new Array<any>();
            this._isSetTwoTag = false;
            this._oneIndex = -1;
            this._twoIndex = -1;
            this._btnBarSelectIdx = -1;
            return;
        }

        public setTabBar(arg1: int, arg2: int): void
        {
            this._oneIndex = arg1;
            this._twoIndex = arg2;
            this._btnBarSelectIdx = arg1;
            this._isSetTwoTag = true;
            this._buttonBar.selectedIndex = arg1;
            this._textBar.dataProvider = this._secondTagDp[arg1];
            this._textBar.selectedIndex = this._twoIndex;
            return;
        }

        /* internal */ /* var */_firstTagDp: Array<any>;

        /* internal */ /* var */_secondTagDp: Array<any>;

        /* internal */ /* var */_buttonBar: GMarketButtonBar;

        /* internal */ /* var */_textBar: GTextBar;

        /* internal */ /* var */_btnBarSelectIdx: int;

        /* internal */ /* var */_isSetTwoTag: Boolean=false;

        /* internal */ /* var */_oneIndex: int=-1;

        /* internal */ /* var */_twoIndex: int=-1;
    }
